<%@ page language="Java" import="descriptor.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<%
	AcademicSupListDescriptor academicSupList = (AcademicSupListDescriptor)request.getAttribute("AcademicSupList");
	AcademicSupListDescriptor academicSupList2 = (AcademicSupListDescriptor)request.getAttribute("AcademicSupList2");
	OfferListDescriptor offerList = (OfferListDescriptor)request.getAttribute("personalOfferList");
	String dep = (String)request.getAttribute("dep");
	String error1 = (String)request.getAttribute("error1");
	String error2 = (String)request.getAttribute("error2");
	
	String notif = "";
	if(error2 != null)
	{
		notif = "<p style=\"color:red; font-size: 10px;\">" + error2 + "<p>";
	}

%>

<html>
	<jsp:include page="StudentHeader.jsp" >
		<jsp:param name="pageTitle" value="Work Placement Management System - Student" />
	</jsp:include>
	<body  OnLoad="showmenu(document.getElementById('smenu5'));">
		<jsp:include page="StudentPageHeader.jsp"></jsp:include> 
		<div id="container">
			<jsp:include page="StudentMenu.jsp" ></jsp:include>
			<div id="content">
				<h3 class="posttitle">Student - Send a Query</h3>
				<div class="entry">
					<%= notif %>
					<%
						if(academicSupList != null)
						{
							int sizeList = academicSupList.sizeAcademicSupList();
							if(sizeList > 0)
							{
					%>
					<form name="frmDepAcademicSup"  method="post">
						<input type="hidden" name="action" value="viewAcademicSup"> 
						<fieldset>
							<legend>Department of the Academic Supervisor</legend>
							<p> Select the department of the Academic Supervisor :	
								<select OnChange="document.frmDepAcademicSup.submit();" name="AcademicSupDep">    
									<option value="">Select the department: </option>
							<%
										for(int i=0; i< sizeList; i++)
										{
											String academicSupDep = academicSupList.getAcademicSupDescriptors().get(i).getDepartment();
											String selected = "";
											if(dep !=null && dep.equals(academicSupDep))
											{
												selected = "selected";
											}
							%>
									<option value="<%= academicSupDep %>" <%= selected %>><%= academicSupDep %></option>
								
							<%			}
							%>
								</select> 
							</p>
						</fieldset>
					</form>
					<form name="frmNameAcademicSup" method="post">
						<input type="hidden" name="action" value="sentQuery">
						<fieldset>
							<p> Select an Academic Supervisor :	
								<select id="select" OnChange="enableSendBtn('select','sendBtn');" name="academicSupID">  
									<option value="">Select a Supervisor: </option>  
							<%
									if(academicSupList2 != null)
									{
										int size = academicSupList2.sizeAcademicSupList();
										for(int i=0; i< size; i++)
										{
											String academicSupName = academicSupList2.getAcademicSupDescriptors().get(i).getName();
											int academicSupID = academicSupList2.getAcademicSupDescriptors().get(i).getUserId();
							%>
									<option value="<%= academicSupID %>"><%= academicSupName %></option>
								
							<%			}
									}
							%>
								</select> 
							</p>
							<p>Select an Offer : 	
								<select name="offerID"> 
									<option value="-1">Select a Supervisor: </option>  
							<%
									if(offerList != null)
									{
										int size = offerList.sizeOfferList();
										if(size > 0)
										{
											for(int i=0; i< size; i++)
											{
												String offerName = offerList.getOfferList().get(i).getName();
												int offerID = offerList.getOfferList().get(i).getId();
							%>
									<option value="<%= offerID %>"><%= offerName %></option>
								
							<%				}
										}
									}
							%>
									<option value="0">Other Offer (Precise the name in the message)</option> 
								</select>
							</p>
							<p>Message to the supervisor:<br>
								<textarea name="msgQuery" rows="5" cols="60"> ... </textarea>
							</p>
							<fieldset>
								<p><button id="sendBtn" type="submit">Send</button> <button type="reset">Clear</button></p>
							</fieldset>
						</fieldset>
					</form>
					<%
							}
							else
							{
								if(error1 != null)
								{
					%>
									<p><%= error1 %></p>
					<%
								}
							}
						}
					%>
				</div>
	    	</div>
			<jsp:include page="StudentPageFooter.jsp"></jsp:include>
		</div>	
	</body>
</html>